package com.ruoyi.aqsc.service.impl;

import com.ruoyi.aqsc.domain.Label;
import com.ruoyi.aqsc.mapper.LabelMapper;
import com.ruoyi.aqsc.service.LabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Primary
public class LabelServiceImpl implements LabelService {
    /**
     * LabelServiceImpl需要调用LabelMapper才能操作数据库的数据
     * @param label
     * @return
     */
    @Autowired
    private LabelMapper mapper;
    @Override
    public boolean saveOrUpdata(Label label) {
        if(label.getId()==null){
            return mapper.insertLabel(label)==1?true:false;
        }
        return mapper.updateLabel(label)==1?true:false;
    }

    @Override
    public boolean removeById(Integer id) {
        return mapper.deleteById(id)==1;
    }

    @Override
    public boolean removeByIds(Integer[] ids) {
        int flag =0;
        for(int i=0;i<ids.length;i++){
            flag+=mapper.deleteById(ids[i]);
        }
        return flag==ids.length;
    }

    @Override
    public Label queryById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public List<Label> queryLabels(Label label) {
        return mapper.select(label);
    }
}
